<template>
  <div class="page">
    <!-- 顶部导航栏 -->
    <header class="header">
      <div class="logo">能力图谱</div>
    </header>

    <!-- 主体内容区域 -->
    <div class="main-content">
      <!-- 左侧栏（带有文本超链接的图谱选择） -->
      <aside class="left-sidebar">
        <a
          v-for="(visible, category) in categoryVisible"
          :key="category"
          href="#"
          @click="toggleCategoryVisibility(category)"
          class="sidebar-item"
          :class="{ 'sidebar-item-active': visible }"
        >
          <span :style="{ color: categoryVisible[category] ? getCategoryColor(category) : '#999' }">●</span>  {{ category }}
        </a>
        <a href="#" @click="showAllCategories" class="sidebar-item sidebar-item-all" style="display:flex;justify-content:end">🔄重置</a>

        <!-- 详情展示区域（也可写选中关系或说明） -->
        <div v-if="selectedNodeDetail" class="node-detail">
          <h4>{{ selectedNodeDetail.name }}</h4>
          <p v-if="selectedNodeDetail.description" 
            @click="handleDescriptionClick(selectedNodeDetail)"
            :class="{ 'clickable-description': selectedNodeDetail.citation }">
            {{ selectedNodeDetail.description }}
          </p>
          <button @click="selectedNodeDetail = null">关闭</button>
        </div>
      </aside>

      <!-- 中央区域（百度ECharts关系网络图） -->
      <section class="main-visual">
        <div id="echarts-container" style="height: 600px;"></div>
      </section>

      <!-- 右侧栏（包含AI聊天功能） -->
      <aside class="right-sidebar">
        <div class="chat-container">
          <div class="status-indicator">
            <span class="online-dot"></span>
            <h3 class="assistant-title">游戏策划AI小助手</h3>
          </div>
          <div class="message-list">
            <div v-for="(msg, index) in messages" :key="index" :class="['message', msg.role]">
              <div class="avatar">{{ msg.role === 'user' ? '👤' : '🤖' }}</div>
              <div class="bubble">{{ msg.text }}</div>
            </div>
            <div v-if="isTyping" class="message ai">
              <div class="avatar">🤖</div>
              <div class="bubble typing">{{ currentAIText }}<span class="cursor">|</span></div>
            </div>
          </div>
          <div class="input-area">
            <input v-model="userInput" @keyup.enter="sendMessage" placeholder="输入消息..." :disabled="isWaitingResponse"/>
            <button @click="sendMessage" :disabled="isWaitingResponse">发送</button>
          </div>
        </div>
      </aside>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  name: 'AbilityMapPage',
  data() {
    return {
      messages: [],
      userInput: "",
      currentAIText: "",
      isTyping: false,
      isWaitingResponse: false,
      typingSpeed: 20,
      typingTimer: null,
      abortController: null, // 用于取消请求
      graphOption: null,
      // 存储类别显示状态
      categoryVisible: {
        '游戏设计能力': true,
        '技术理解与整合': true,
        '用户体验与市场洞察': true,
        '团队协作与管理': true,
        '数据分析与优化': true,
        '思考力': true,
        '决策力': true,
        '执行力': true
      },
      selectedNode: null,
      selectedNodeDetail: null
    };
  },
  mounted() {
    this.initializeGraph();
  },
  methods: {
    handleDescriptionClick(node) {
    if (node.citation) {
      window.open(node.citation, '_blank');
    }
  },
    async sendMessage() {
      if (!this.userInput.trim() || this.isWaitingResponse) return;

      // 1. 添加用户消息
      this.messages.push({
        role: "user",
        text: this.userInput,
      });
      const userMessage = this.userInput;
      this.userInput = "";
      this.isWaitingResponse = true;

      // 2. 创建AbortController以便取消请求
      this.abortController = new AbortController();

      try {
        // 构建请求URL（替换为你的实际appId和secretKey）
        const appId = "YTk2ejbUc1TDsr0Q28WbpDBM3P6TtOdG";
        const secretKey = "VF9BaoswFxgbi1oA3cFLKIShRZg4mqgm";
        const url = `https://agentapi.baidu.com/assistant/conversation?appId=${appId}&secretKey=${secretKey}`;

        // 构建请求体
        const requestBody = {
          message: {
            content: {
              type: "text",
              value: {
                showText: userMessage
              }
            }
          },
          source: "appAnsId",
          from: "openapi",
          openId: localStorage.getItem('id') // 使用本地存储的用户ID
        };

        const response = await fetch(url, {
          method: "POST",
          headers: {"Content-Type": "application/json"},
          body: JSON.stringify(requestBody),
          signal: this.abortController.signal,
        });

        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }

        if (!response.body) {
          throw new Error("ReadableStream not supported in this browser");
        }

        // 3. 处理流式响应
        const reader = response.body.getReader();
        const decoder = new TextDecoder("utf-8");
        let fullText = "";
        let buffer = "";
        let reading = true;

        while (reading) {
          const {done, value} = await reader.read();
          reading = !done;

          if (value) {
            buffer += decoder.decode(value, {stream: true});

            // 处理可能的多行数据
            const lines = buffer.split(/\r\n|\n|\r/);
            buffer = lines.pop() || "";

            for (const line of lines) {
              if (line.startsWith("data:")) {
                try {
                  const jsonStr = line.substring(5).trim();
                  if (jsonStr) {
                    const data = JSON.parse(jsonStr);
                    const newText = this.extractAIText(data);
                    if (newText) {
                      fullText += newText;
                      this.playTypingEffect(newText);
                    }
                  }
                } catch (err) {
                  console.error("解析错误:", err);
                }
              }
            }
          }
        }

        // 处理剩余缓冲区数据
        if (buffer.trim()) {
          try {
            const data = JSON.parse(buffer.substring(5).trim());
            const newText = this.extractAIText(data);
            if (newText) {
              fullText += newText;
              this.playTypingEffect(newText);
            }
          } catch (err) {
            console.error("最终解析错误:", err);
          }
        }

        // 添加完整的AI响应
        this.messages.push({
          role: "ai",
          text: fullText,
        });
      } catch (err) {
        if (err.name === "AbortError") {
          console.log("请求已被取消");
        } else {
          console.error("请求失败:", err);
          this.messages.push({
            role: "ai",
            text: "抱歉，AI暂时无法响应，请稍后再试。",
          });
        }
      } finally {
        this.isWaitingResponse = false;
        this.isTyping = false;
        this.currentAIText = "";
        clearInterval(this.typingTimer);
        this.abortController = null;
      }
    },

    // 取消请求的方法
    cancelRequest() {
      if (this.abortController) {
        this.abortController.abort();
      }
    },

    // 从API响应中提取AI文本
    extractAIText(data) {
      let result = "";
      if (data?.data?.message?.content) {
        data.data.message.content.forEach(item => {
          if (item.data?.text) {
            result += item.data.text;
          }
        });
      }
      return result;
    },

    // 打字机效果
    playTypingEffect(fullText) {
      this.isTyping = true;
      clearInterval(this.typingTimer);

      let i = 0;
      this.typingTimer = setInterval(() => {
        if (i < fullText.length) {
          this.currentAIText += fullText.charAt(i);
          i++;
        } else {
          clearInterval(this.typingTimer);
        }
      }, this.typingSpeed);
    },

    // 初始化ECharts图表
    initializeGraph() {
      const myChart = echarts.init(document.getElementById('echarts-container'));
      const option = {
        title: {
          subtext: '基于行业标准、资深策划经验及学术分析',
          left: 'center',
          bottom: -25,
          textStyle: {
            fontSize: 18,
            color: '#333'
          },
          subtextStyle: {
            fontSize: 12,
            color: '#666'
          }
        },
        tooltip: {
          trigger: 'item',
          formatter: function(params) {
            if (params.dataType === 'node') {
              return `${params.name}<br/>${params.data?.description || ''}<br/>重要性：${params.value || 0}`;
            }
            return `${params.data.source} → ${params.data.target}<br/>关系：${params.data.name || '关联'}${params.data?.description ? '<br/>说明：' + params.data.description : ''}`;
          }
        },
        legend: {
          show: false,
        },
        series: [{
          type: 'graph',
          layout: 'force',
          force: {
            repulsion: 1500,
            edgeLength: [100, 300],
            layoutAnimation: true
          },
          roam: true,
          draggable: true,
          focusNodeAdjacency: true,
          edgeSymbol: ['none', 'arrow'],
          edgeSymbolSize: 8,
          categories: [
            { name: '游戏设计能力', itemStyle: { color: '#c23531' } },
            { name: '技术理解与整合', itemStyle: { color: '#2f4554' } },
            { name: '用户体验与市场洞察', itemStyle: { color: '#61a0a8' } },
            { name: '团队协作与管理', itemStyle: { color: '#d48265' } },
            { name: '数据分析与优化', itemStyle: { color: '#91c7ae' } },
            { name: '思考力', itemStyle: { color: '#749f83' } },
            { name: '决策力', itemStyle: { color: '#ca8622' } },
            { name: '执行力', itemStyle: { color: '#bda29a' } }
          ],
          nodes: [
            // 游戏设计能力核心节点
            { name: '游戏设计能力', description: '构建核心玩法规则与数值体系，设计关卡流程与叙事框架，实现玩法与故事的有机结合',value: 25, category: 0, symbolSize: 50, isCore: true, show: true },
            { name: '系统架构', value: 20, category: 0, symbolSize: 40, citation: 'https://www.hrloo.com/news/284992.html', 
              description: '设计核心玩法规则、经济系统、战斗机制等', show: true },
            { name: '数值平衡', value: 20, category: 0, symbolSize: 40, citation: 'https://www.oh100.com/peixun/youxidongman/114975.html', 
              description: '优化角色属性、经济模型、概率体系等', show: true },
            { name: '关卡设计', value: 18, category: 0, symbolSize: 38, citation: 'https://www.hxsd.com/content/15766/', 
              description: '构建地图布局、难度曲线、交互场景', show: true },
            { name: '叙事设计', value: 18, category: 0, symbolSize: 38, citation: 'https://www.hxsd.com/content/15766/', 
              description: '编写剧情、世界观、角色故事线', show: true },
            
            // 技术理解与整合核心节点
            { name: '技术理解与整合', description: '掌握引擎工具特性，协调程序实现方案，将设计需求转化为可执行技术方案', value: 25, category: 1, symbolSize: 50, isCore: true, show: true },
            { name: '引擎工具', value: 18, category: 1, symbolSize: 38, citation: 'https://www.nowcoder.com/discuss/387348958597718016?toCommentId=13877197', 
              description: '熟悉Unity、Unreal等开发引擎', show: true },
            { name: '编程基础', value: 18, category: 1, symbolSize: 38, citation: 'http://paiyouwang.com/256815.html', 
              description: '理解脚本语言（如Lua、Python）及算法逻辑', show: true },
            { name: '美术协作', value: 16, category: 1, symbolSize: 36, citation: 'https://blog.csdn.net/broadview2006/article/details/80123928?locationNum=14&fps=1', 
              description: '与美术团队沟通界面、特效、模型需求', show: true },
            
            // 用户体验与市场洞察核心节点
            { name: '用户体验与市场洞察',  description: '分析玩家行为数据，优化交互体验，结合市场趋势设计符合用户需求的玩法内容',value: 25, category: 2, symbolSize: 50, isCore: true, show: true },
            { name: '玩家行为分析', value: 18, category: 2, symbolSize: 38, citation: 'https://www.shangyexinzhi.com/article/2252092.html', 
              description: '通过数据监控玩家留存、付费习惯等', show: true },
            { name: '交互设计', value: 18, category: 2, symbolSize: 38, citation: 'https://blog.csdn.net/broadview2006/article/details/80123928?locationNum=14&fps=1', 
              description: '优化UI/UX，确保操作流畅直观', show: true },
            { name: '市场调研', value: 16, category: 2, symbolSize: 36, citation: 'https://www.hrloo.com/news/284992.html', 
              description: '分析竞品趋势、用户需求与付费模式', show: true },
            
            // 团队协作与管理核心节点
            { name: '团队协作与管理',  description: '制定开发流程与标准，协调跨部门资源，把控项目进度并解决协作冲突',value: 25, category: 3, symbolSize: 50, isCore: true, show: true },
            { name: '跨部门沟通', value: 18, category: 3, symbolSize: 38, citation: 'https://www.hrloo.com/news/284992.html', 
              description: '协调程序、美术、测试团队需求', show: true },
            { name: '项目管理', value: 18, category: 3, symbolSize: 38, citation: 'https://www.shangyexinzhi.com/article/2252092.html', 
              description: '制定开发周期、优先级及风险评估', show: true },
            { name: '抗压能力', value: 15, category: 3, symbolSize: 35, citation: 'https://www.oh100.com/peixun/youxidongman/114975.html', 
              description: '应对需求变更、Deadline压力及团队冲突', show: true },
            
            // 数据分析与优化核心节点
            { name: '数据分析与优化',  description: '建立数据埋点模型，通过A/B测试验证设计，持续优化系统平衡与商业化效果',value: 25, category: 4, symbolSize: 50, isCore: true, show: true },
            { name: '数据建模', value: 18, category: 4, symbolSize: 38, citation: 'https://blog.csdn.net/broadview2006/article/details/80123928?locationNum=14&fps=1', 
              description: '设计埋点、收集玩家行为数据', show: true },
            { name: 'A/B测试', value: 16, category: 4, symbolSize: 36, citation: 'https://gameinstitute.qq.com/knowledge/100029', 
              description: '验证玩法调整效果', show: true },
            { name: '商业化设计', value: 16, category: 4, symbolSize: 36, citation: 'http://paiyouwang.com/256815.html', 
              description: '结合数据优化付费点与盈利模式', show: true },
            
            // 高阶维度
            { name: '思考力',  description: '运用系统化设计思维拆解复杂问题，通过竞品逆向分析提出创新解决方案',value: 25, category: 5, symbolSize: 50, isCore: true, show: true },
            { name: '创意发散', value: 18, category: 5, symbolSize: 38, citation: 'https://www.17tex.com/tex/4/323271.html', 
              description: '如头脑风暴、竞品逆向分析', show: true },
            { name: '系统化设计思维', value: 18, category: 5, symbolSize: 38, citation: 'https://gameinstitute.qq.com/knowledge/100029', 
              description: '如"巴图玩家分类法"指导目标设计', show: true },
            
            { name: '决策力',  description: '基于开发成本与玩家体验评估方案优先级，在创新性与可行性间找到平衡点',value: 25, category: 6, symbolSize: 50, isCore: true, show: true },
            { name: '方案取舍', value: 18, category: 6, symbolSize: 38, citation: 'https://www.17tex.com/tex/4/323271.html', 
              description: '如平衡创新性与开发成本', show: true },
            { name: '优先级管理', value: 18, category: 6, symbolSize: 38, citation: 'https://www.nowcoder.com/discuss/387348958597718016?toCommentId=13877197', 
              description: '如核心玩法优先于边缘功能', show: true },
            
            { name: '执行力',  description: '将设计文档转化为可落地方案，跟进开发全流程，根据测试反馈快速迭代优化',value: 25, category: 7, symbolSize: 50, isCore: true, show: true },
            { name: '需求落地', value: 18, category: 7, symbolSize: 38, citation: 'https://www.17tex.com/tex/4/323271.html', 
              description: '从文档到代码/美术资源的全流程跟进', show: true },
            { name: '持续优化', value: 18, category: 7, symbolSize: 38, citation: 'https://gameinstitute.qq.com/knowledge/100029', 
              description: '根据测试反馈迭代设计', show: true }
          ],
          links: [
            // 游戏设计能力内部关联
            { source: '游戏设计能力', target: '系统架构', name: '包含', lineStyle: { width: 2 }},
            { source: '游戏设计能力', target: '数值平衡', name: '包含', lineStyle: { width: 2 }},
            { source: '游戏设计能力', target: '关卡设计', name: '包含', lineStyle: { width: 2 }},
            { source: '游戏设计能力', target: '叙事设计', name: '包含', lineStyle: { width: 2 }},
            
            // 技术理解与整合内部关联
            { source: '技术理解与整合', target: '引擎工具', name: '包含', lineStyle: { width: 2 }},
            { source: '技术理解与整合', target: '编程基础', name: '包含', lineStyle: { width: 2 }},
            { source: '技术理解与整合', target: '美术协作', name: '包含', lineStyle: { width: 2 }},
            
            // 用户体验与市场洞察内部关联
            { source: '用户体验与市场洞察', target: '玩家行为分析', name: '包含', lineStyle: { width: 2 }},
            { source: '用户体验与市场洞察', target: '交互设计', name: '包含', lineStyle: { width: 2 }},
            { source: '用户体验与市场洞察', target: '市场调研', name: '包含', lineStyle: { width: 2 }},
            
            // 团队协作与管理内部关联
            { source: '团队协作与管理', target: '跨部门沟通', name: '包含', lineStyle: { width: 2 }},
            { source: '团队协作与管理', target: '项目管理', name: '包含', lineStyle: { width: 2 }},
            { source: '团队协作与管理', target: '抗压能力', name: '包含', lineStyle: { width: 2 }},
            
            // 数据分析与优化内部关联
            { source: '数据分析与优化', target: '数据建模', name: '包含', lineStyle: { width: 2 }},
            { source: '数据分析与优化', target: 'A/B测试', name: '包含', lineStyle: { width: 2 }},
            { source: '数据分析与优化', target: '商业化设计', name: '包含', lineStyle: { width: 2 }},
            
            // 思考力内部关联
            { source: '思考力', target: '创意发散', name: '包含', lineStyle: { width: 2 }},
            { source: '思考力', target: '系统化设计思维', name: '包含', lineStyle: { width: 2 }},
            
            // 决策力内部关联
            { source: '决策力', target: '方案取舍', name: '包含', lineStyle: { width: 2 }},
            { source: '决策力', target: '优先级管理', name: '包含', lineStyle: { width: 2 }},
            
            // 执行力内部关联
            { source: '执行力', target: '需求落地', name: '包含', lineStyle: { width: 2 }},
            { source: '执行力', target: '持续优化', name: '包含', lineStyle: { width: 2 }},
            
            // 能力关联网络 - 设计能力 ↔ 技术理解
            { source: '系统架构', target: '引擎工具', name: '依赖关系', lineStyle: { width: 2, color: '#c23531' },
              description: '系统设计需技术实现支撑（如引擎功能）' },
            { source: '系统架构', target: '编程基础', name: '依赖关系', lineStyle: { width: 2, color: '#c23531' },
              description: '系统设计需技术实现支撑（如脚本编写）' },
            { source: '数值平衡', target: '编程基础', name: '依赖关系', lineStyle: { width: 2, color: '#c23531' },
              description: '数值平衡依赖算法验证（如战斗公式、经济模拟）' },
            
            // 能力关联网络 - 用户体验 ↔ 数据分析
            { source: '玩家行为分析', target: '交互设计', name: '数据驱动', lineStyle: { width: 2, color: '#61a0a8' },
              description: '玩家行为数据驱动交互优化（如界面调整、任务难度）' },
            { source: '市场调研', target: '叙事设计', name: '数据驱动', lineStyle: { width: 2, color: '#61a0a8' },
              description: '市场调研指导剧情与世界观设计（如题材选择、用户偏好）' },
            
            // 能力关联网络 - 团队协作 ↔ 项目管理
            { source: '跨部门沟通', target: '项目管理', name: '协作流程', lineStyle: { width: 2, color: '#d48265' },
              description: '跨部门沟通效率影响开发进度' },
            { source: '项目管理', target: '编程基础', name: '协作流程', lineStyle: { width: 2, color: '#d48265' },
              description: '风险评估需结合技术可行性与设计目标' },
            
            // 能力关联网络 - 创意能力 ↔ 执行能力
            { source: '创意发散', target: '需求落地', name: '依赖关系', lineStyle: { width: 2, color: '#749f83' },
              description: '创新玩法需通过原型测试验证可行性' },
            { source: '系统化设计思维', target: '需求落地', name: '依赖关系', lineStyle: { width: 2, color: '#749f83' },
              description: '设计文档需细化至可执行需求（如流程图、配置表）' },
            
            // 高阶维度关联
            { source: '系统化设计思维', target: '系统架构', name: '思维支持', lineStyle: { width: 2, color: '#749f83' }},
            { source: '优先级管理', target: '项目管理', name: '决策支持', lineStyle: { width: 2, color: '#ca8622' }},
            { source: '方案取舍', target: '系统架构', name: '决策支持', lineStyle: { width: 2, color: '#ca8622' }},
            { source: '需求落地', target: '编程基础', name: '执行支持', lineStyle: { width: 2, color: '#bda29a' }},
            { source: '需求落地', target: '美术协作', name: '执行支持', lineStyle: { width: 2, color: '#bda29a' }},
            
            // 其他重要关联
            { source: '数据建模', target: '玩家行为分析', name: '数据支持', lineStyle: { width: 2, color: '#91c7ae' }},
            { source: 'A/B测试', target: '交互设计', name: '优化手段', lineStyle: { width: 2, color: '#91c7ae' }},
            { source: '商业化设计', target: '数值平衡', name: '设计应用', lineStyle: { width: 2, color: '#91c7ae' },
              description: '数值平衡→经济模型优化→付费点设计' }
          ],
          lineStyle: {
            color: 'source',
            curveness: 0.1,
            width: 1.5,
            opacity: 0.8
          },
         emphasis: {
            scale: true,
            itemStyle: {
              shadowBlur: 20,
              shadowColor: 'rgba(0, 0, 0, 0.3)'
            },
            label: {
              show: true,
              fontSize: 16
            },
            edgeLabel: {
              show: true,
              fontSize: 12
            }
          },
          animationDuration: 500, // 节点和边的动画过渡时间
          animationEasingUpdate: 'quinticInOut' // 动画缓动效果
        }]
      };

      this.graphOption = option;
      myChart.setOption(option);
      
      // 监听节点点击事件，实现导航定位
      myChart.on('click', (params) => {
        if (params.dataType === 'node') {
          this.selectedNode = params.name;
          this.selectedNodeDetail = params.data;
        }
      });
    },

    // 切换类别可见性
    toggleCategoryVisibility(category) {
      this.categoryVisible[category] = !this.categoryVisible[category];
      this.updateGraphVisibility();
    },

    // 显示所有类别
    showAllCategories() {
      Object.keys(this.categoryVisible).forEach(key => {
        this.categoryVisible[key] = true;
      });
      this.updateGraphVisibility();
    },

    // 更新图谱可见性
      updateGraphVisibility() {
        const myChart = echarts.getInstanceByDom(document.getElementById('echarts-container'));
        if (myChart && this.graphOption) {
          const option = this.graphOption;
          
          // 更新节点可见性
          option.series[0].nodes.forEach(node => {
            const categoryName = option.series[0].categories[node.category].name;
            const isVisible = this.categoryVisible[categoryName];
            
            // 控制节点和标签可见性
            node.show = isVisible;
            if (node.itemStyle) {
              node.itemStyle.opacity = isVisible ? 1 : 0;
            } else {
              node.itemStyle = { opacity: isVisible ? 1 : 0 };
            }
          });
        
        // 更新边可见性
        option.series[0].links.forEach(link => {
          const sourceNode = option.series[0].nodes.find(n => n.name === link.source);
          const targetNode = option.series[0].nodes.find(n => n.name === link.target);
          
          // 如果源节点和目标节点都显示，则边显示，否则隐藏
          link.lineStyle.opacity = (sourceNode && sourceNode.show && targetNode && targetNode.show) ? 0.8 : 0;
        });

        myChart.setOption(option);
      }
    },
    
    // 获取类别颜色
    getCategoryColor(category) {
      const categories = this.graphOption?.series[0]?.categories || [];
      const cat = categories.find(c => c.name === category);
      return cat?.itemStyle?.color || '#333';
    },
    
    // 聚焦到指定节点
    focusOnNode(nodeName) {
      const myChart = echarts.getInstanceByDom(document.getElementById('echarts-container'));
      if (!myChart) return;

      const nodes = this.graphOption.series[0].nodes;
      const dataIndex = nodes.findIndex(node => node.name === nodeName && node.show);

      if (dataIndex === -1) return;

      // 聚焦高亮
      myChart.dispatchAction({
        type: 'focusNodeAdjacency',
        seriesIndex: 0,
        dataIndex
      });

      // 显示 tooltip
      myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex
      });

      this.selectedNode = nodeName;
      this.selectedNodeDetail = nodes[dataIndex];
    }
  },
  beforeUnmount() {
    this.cancelRequest();
    clearInterval(this.typingTimer);
  }
};
</script>

<style scoped>
.echarts-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.clickable-description {
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  
}
.clickable-description:hover {
  text-decoration: underline;
  color: #157ac0;
}
.citation-link {
  color: #409EFF;
  cursor: pointer;
  text-decoration: underline;
  transition: opacity 0.3s;
}

.citation-link:hover {
  opacity: 0.8;
}
.echarts-chart-node[style*="display: none"] {
  opacity: 0 !important;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  background-color: #333;
  color: white;
  padding: 1rem;
  font-size: 1.5rem;
  font-weight: bold;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar-item {
  display: block;
  padding: 0.5rem 0;
  color: #333;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s;
}

.sidebar-item:hover {
  color: #007bff;
  background-color: #e9ecef;
  padding-left: 0.5rem;
}

.sidebar-item-active {
  font-weight: bold;
  color: #007bff;
}

.bubble {
  padding: 0.75rem;
  border-radius: 10px;
  max-width: 80%;
}

.user .bubble {
  background-color: #007bff;
  color: white;
}

.ai .bubble {
  background-color: #e9ecef;
  color: #333;
}

.typing .cursor {
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.input-area {
  display: flex;
  padding: 1rem;
  border-top: 1px solid #ddd;
}

.input-area input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-right: 0.5rem;
}

.input-area button {
  padding: 0.5rem 1rem;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.input-area button:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
}
.node-detail {
  margin-top: 20px;
  padding: 12px;
  background: #f9f9f9;
  border-left: 4px solid #409EFF;
  font-size: 14px;
  line-height: 1.6;
  height: 130px;
  position: relative;
}
.node-detail h4 {
  margin: 0 0 8px;
  font-size: 16px;
  color: #333;
}
.node-detail button {
  margin-top: 10px;
  background: none;
  border: none;
  color: #409EFF;
  cursor: pointer;
  position: absolute;
  top: 5px;
  right: 5px;
}

/* 页面布局 */
.page {
  font-family: "Source Han Sans", sans-serif;
  padding: 20px;
}

/* 顶部导航栏 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #1D1D1D;
  padding: 10px;
}

.logo {
  color: #EEEEEE;
  font-size: 18px;
}

/* 主体内容区域 */
.main-content {
  display: flex;
  margin-top: 30px;
  margin-bottom: 30px;
}

/* 左侧栏（文本超链接） */
.left-sidebar {
  width: 25%;
  background-color: #1D1D1D;
  padding: 10px;
  border-right: 1px solid #ddd;
  height: 580px;
}

.sidebar-item {
  display: block;
  color: #BBBBBB;
  padding: 10px;
  text-decoration: none;
  border-bottom: 1px solid #555;
}

.sidebar-item:hover {
  background-color: #333;
  color: #FFFFFF;
}

/* 中间ECharts图谱区域 */
.main-visual {
    position: relative;
  /* background-image: url('@/assets/picture/skybox.jpg'); */
  width: 50%;
  height: 600px;
  border: 2px solid #e4e7ed;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
}

/* 右侧栏 */
.right-sidebar {
  width: 25%;
  background-color: #1D1D1D;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border-left: 1px solid #ddd;
  height: 600px;
  overflow-y: auto;
}

/* AI聊天区域 */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}


.message-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  /* 添加滚动条隐藏样式 */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.message-list::-webkit-scrollbar {
  width: 0;
  background: transparent;
}
.message {
  display: flex;
  margin-bottom: 12px;
}

.avatar {
  margin-right: 10px;
  font-size: 20px;
}

.bubble {
  max-width: 70%;
  padding: 10px 15px;
  border-radius: 18px;
  line-height: 1.4;
}

.user {
  justify-content: flex-end;
   flex-direction: row-reverse;
}

.user .avatar {
  margin-left: 10px;  /* 原为margin-right */
  margin-right: 0;
}

/* 用户消息气泡 */
.user .bubble {
  margin-left: auto; /* 自动左外边距实现右对齐 */
}

.ai {
  justify-content: flex-start;
}

.ai .bubble {
  background: white;
  border: 1px solid #eee;
}

.typing {
  position: relative;
}

.cursor {
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.input-area {
  display: flex;
  padding: 10px;
  border-top: 1px solid #ddd;
  background: white;
}

.input-area input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 20px;
}

.input-area button {
  margin-left: 8px;
  padding: 8px 16px;
  background: #1890ff;
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
}
.right-sidebar {
  width: 25%;
  background-color: #1D1D1D;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  border-left: 1px solid #ddd;
  height: 560px; /* 修改为视口高度百分比 */
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 90%;
}


/* AI聊天区域 */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}


/* 消息 */
.message {
  display: flex;
  margin-bottom: 12px;
}

.avatar {
  margin-right: 10px;
  font-size: 20px;
}

/* 用户消息气泡 */
.user .bubble {
  background: #1890ff; /* Blue for user */
  color: white;
  border-radius: 18px;
  padding: 12px 16px;
  max-width: 80%; /* Increase message width */
  line-height: 1.5; /* Improve readability */
  word-wrap: break-word; /* Allow long words to break */
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Soft shadow */
  border: 1px solid #1890ff; /* Border matching the background */
}

/* AI消息气泡 */
.ai .bubble {
  background: #fff;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 18px;
  padding: 12px 16px;
  max-width: 80%;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Soft shadow */
}

/* 打字机效果 */
.typing .bubble {
  background: #fff;
  color: #1890ff;
  border: 1px solid #ddd;
  padding: 12px 16px;
  max-width: 80%;
  font-style: italic;
  word-wrap: break-word;
}

.cursor {
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* 输入区 */
.input-area {
  display: flex;
  padding: 10px;
  border-top: 1px solid #ddd;
  background: #2C2C2C;
  border-radius: 10px;
}

.input-area input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 20px;
  margin-right: 8px;
  background-color: #444; /* Darker input background */
  color: #fff;
}

.input-area button {
  padding: 8px 16px;
  background: #1890ff;
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.input-area button:hover {
  background: #157ac0; /* Darker shade on hover */
}

/* 背景和对话框阴影 */
.chat-container {
  border-radius: 8px;
  padding: 10px;
}
/* 在线状态指示器 */
.status-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
}

.online-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: #00ff00;
  border-radius: 50%;
  margin-right: 8px;
  animation: pulse 1.5s infinite;
  box-shadow: 0 0 8px rgba(0, 255, 0, 0.5);
}

.assistant-title {
  color:white;
  font-size: 16px;
  margin: 0;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}
</style>